package com.superyee.commonlib.entity;



import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

/**
 * 请求服务器返回实体
 */
public class DataListResponse<T> {
    public int current_page;
    public int last_page;
    public int per_page;
    public T data;
    public String first_page_url;
    public String prev_page_url;
    public String next_page_url;
    public String last_page_url;
    public String path;
    public int total;
    public int from;
    public int to;
    public String param;
    public Object object;
    public String timestamp;

    public boolean isFirstPage() {
        return current_page <= 1;
    }

    public boolean isLastPage() {
        return current_page >= last_page;
    }

    public void setAdapter(BaseQuickAdapter adapter) {
        adapter.isUseEmpty(true);
        //预加载
        adapter.setPreLoadNumber(4);
        if (!isFirstPage()) {
            if (data != null) {
                adapter.addData((List) data);
            }
        } else {
            adapter.setNewData((List) data);
        }
        if (isLastPage()) {
            adapter.loadMoreEnd(true);
        } else {
            adapter.loadMoreComplete();
            adapter.setEnableLoadMore(true);
        }
    }
}
